/*
 * WitnessButton.java
 * 
 * Created on Apr 9, 2009, 2:28:37 AM
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package portfolio.ampl;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import misellanea.Miscellanea;
import portfolio.mainScreen;

/**
 *
 * @author ACA
 */
public class WitnessButton extends JButton implements ActionListener 
{
    private mainScreen  mainFrame;
    //private JTextArea jta;

    public WitnessButton (mainScreen mainFrameParam)
    {
        super ("Witness");

        mainFrame = mainFrameParam;
        this.addActionListener(this);

        return;
    }
    /***********************************************************/
    public void actionPerformed(ActionEvent e) {
        String sAcctionCommand = e.getActionCommand ();
        System.out.println (sAcctionCommand);
        Vector vStocksReturn = null; //new Vector ();

        try {
            //Vector vReturnSeriesHeader = portfolioDB.describeReturnSeriesTable ("returnSeries");
//            vStocksReturn = portfolioDB.createWitnessTable (sAcctionCommand, vTermTimeLine);

            AmplFrontEnd ampl = new AmplFrontEnd ("ampl");
            if (ampl != null) { // test for vital signs                    
//                Vector vReturnSeriesHeader = portfolioDB.describeReturnSeriesTable ("returnSeries");
//                double [][] dReturnSeries = miscellaneaDB.selectReturnSeriesTable ("witness", vReturnSeriesHeader);
//                Vector vWeights = ampl.createAmplDataFile ("Witness portfolio.",
//                                                           jta, portfolioDB, muText.getText(),
//                                                           vReturnSeriesHeader,
//                                                           vStocksReturn,
//                                                           miscellaneaDB.selectTradedateFromReturnSeriesTable ("witness"),
//                                                           dReturnSeries);

//                double [] dWReturn = miscellaneaDB.getWeightedReturn (dReturnSeries, vWeights);
//                double dReturn     = Miscellanea.getReturn(dWReturn,  dWReturn.length);
//                double dVariance   = Miscellanea.getVar (dWReturn);
//                Double DRisk       = new Double (Math.sqrt(dVariance));
//                Double DReturn     = new Double (dReturn);

                mainFrame.displayMessage("--", "Risk:\t" + "DRisk"/*DRisk.toString()*/ + "\t");
                mainFrame.displayMessage("--", "Return:\t" + "DReturn"/*DReturn.toString()*/ + "\n");


            } else {
                mainFrame.displayMessage("--", "WitnessButton::OptimizeCommand: Error while trying to cominicate with AMPL.");
            }                    
        } catch (Exception exp) {
            mainFrame.displayMessage ("--", exp.toString() + "\n");
            JOptionPane.showMessageDialog (null, exp);                    
        }

    } /* End Method actionPerformed */

} /* End class WitnessButton */
